<template>
    <div>
        <van-list
            v-model="loading"
            :finished="finished"
            finished-text="没有更多了"
            @load="onLoad"
            >
            <ev-mssage v-for="value in list" :key="value._id" :values="value"></ev-mssage>
        </van-list>
    </div>
</template>

<script>
import EvMssage from "@/components/EvMssage"
import {EvaluationMessage} from "@/request/api"

export default {
    components: {
        EvMssage
    },
    data(){
        return {
            list: [],
            loading: false,
            finished: false,
            limit: 3,
            offset: 0
        }
    },
    props: {
        shopId: {
            type: String,
            default: null
        }
    },
    methods: {
        onLoad(){
            // 异步更新数据
            EvaluationMessage({
                id: this.shopId,
                limit: this.limit,
                offset: this.offset
            }).then(res => {
                if(res.status === 200){
                    this.list = res.data
                }

                let data = res.data;
                let lastEl = data[data.length - 1];
                if(lastEl != undefined && (lastEl.id > this.lastId)){
                    this.lastId = lastEl.id;
                    this.list = this.list.concat(data);
                    this.loading = false;
                } else {
                    this.finished = true;
                }
            });
        }
    },
    mounted(){}
}
</script>

<style>

</style>